package com.fan;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;


/**
 * @description: 框架
 * @author: fan
 * @date: 2022/1/24 13:39
 * @version: 1.0
 */
public class MyJFrame extends JFrame {

    /**
     * 荷叶数
     */
    public static final ArrayList<Words> wordsArrayList = new ArrayList<Words>();

    private static Image image = null;

    Random random = new Random();

    static {

        wordsArrayList.add(new Words(0,"inspiration","n.灵感; 鼓舞人心的人(或事物)"));
        wordsArrayList.add(new Words(1,"perspiration","n.汗水;出汗)"));
        wordsArrayList.add(new Words(2,"undertake","vt.&vi.(undertook, undertaken) 着手做;从事;承担"));
        wordsArrayList.add(new Words(3,"analysis","n. ([复]analyses)分析;分解"));
        wordsArrayList.add(new Words(4,"obvious","adj. 明显的，显然的；明确表示的"));
        wordsArrayList.add(new Words(5,"within","prep. 在……里面; 在……范围之内"));
        wordsArrayList.add(new Words(6,"quote","n.引语;引文; (常用复数)引号"));
        wordsArrayList.add(new Words(7,"agriculture","n.农学;农业"));
        wordsArrayList.add(new Words(8,"curious","adj.好奇的;好求知的; 爱打听隐私的"));
        wordsArrayList.add(new Words(9,"scan","vt.浏览;细看;反复察看"));


        try {
            // 读取背景图
            InputStream inputStream = MyJPanel.class.getClassLoader().getResourceAsStream("image/iocImage.png");
            image = ImageIO.read(inputStream);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public MyJFrame() throws HeadlessException {
        //设置显示窗口标题
        this.setTitle("EnglishGame");
        // 图标
        this.setIconImage(image);

        //定时器对象
        Timer timer = new Timer();
        //以毫秒为单位
        int intervel = 500;
        timer.schedule(new TimerTask() {
            public void run() {
               if(wordsArrayList.size() <= EnglishWordsGameMain.TOTAL){
                   wordsArrayList.add(wordsArrayList.get(random.nextInt(wordsArrayList.size())));
               }
            }
        },intervel,intervel);
    }
}
